﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Data.Common;
using Data.Model;
using Data.ViewModel;
using Microsoft.Reporting.WinForms;
using WinForm.Helper;

namespace WinForm.Reports
{
    public partial class PrintRechargeFrm : Form
    {
        public PrintRechargeFrm()
        {
            InitializeComponent();
        }

        /// <summary>
        ///     报表所在目录
        /// </summary>
        private static string _rdlcPath = "Rdlcs\\{0}";

        /// <summary>
        /// 报表名称
        /// </summary>
        private static string _rdlcName;

        /// <summary>
        /// 要打印的充值记录
        /// </summary>
        private List<recharge> _recharges=new List<recharge>();

        public PrintRechargeFrm(List<recharge> recharges,string rdlcName)
        {
            _recharges = recharges;
            _rdlcName = rdlcName;
            InitializeComponent();
        }

        private void PrintRechargeFrm_Load(object sender, EventArgs e)
        {
            string errorMessage = string.Empty;
            try
            {
                reportViewer1.ProcessingMode = ProcessingMode.Local;
                reportViewer1.LocalReport.ReportPath = string.Format(_rdlcPath, _rdlcName);

                if(_recharges!=null&&_recharges.Count>0)
                {
                    //设置参数
                    //var usercardno =
                    //    new ReportParameter("UserCardNo",
                    //        _recharges[0].cardno);
                    //var initalNum =
                    //    new ReportParameter("InitialNum",_recharges[0].initialcash.ToString());
                    //var amount =
                    //    new ReportParameter("AmountNum",
                    //        _recharges[0].amount.ToString());
                    //var total =
                    //    new ReportParameter("TotalNum",
                    //        _recharges[0].balance.ToString());
                    //var ctime =
                    //    new ReportParameter("CharTime",
                    //        _recharges[0].chargetime.ToString());
                    var address =
                        new ReportParameter("CharLockAddress",
                            SystemInfo.OperateAddress);
                    var cuser =
                        new ReportParameter("CharUser",
                            SystemInfo.OperateName);
                    reportViewer1.LocalReport.SetParameters(new List<ReportParameter> { address,cuser });//, initalNum, amount,total,ctime,address,cuser 
                    reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", new List<recharge>(){_recharges[0]}));
                }
                reportViewer1.RefreshReport();
            }
            catch (Exception e1)
            {
                errorMessage = errorMessage + e1.Message;
            }
            if (!string.IsNullOrEmpty(errorMessage))
            {
                MyMessageBox.ShowMessageBoxInfo(errorMessage);
            }
        }
    }
}
